const fs = require('fs')
const path = require('path')
const defaultRoute = 'pages/login' // 第一个页面路由

const getRouter = () => {
	const srcPath = path.resolve(__dirname, './')
	const result = fs.readdirSync(srcPath)
	let router = []
	result.forEach(file => {
		if (file !== 'index.js') {
			const routes = require('./' + file)
			router = [...router, ...routes]
		}
	})
	return router
}

const pageList = getRouter()
const firstPage = pageList.find(item => item.path === defaultRoute)
const routeList = pageList.filter(item => item.path !== defaultRoute)
routeList.unshift(firstPage)

module.exports = routeList